package interviewClassic150;

import org.junit.Test;

public class RemoveDuplicatesMid {
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if (n <= 2) return n;

        int insertIndex = 2;

        // 1,1,1,2,2,3
        for (int i = 2; i < n; i++) {
            if (nums[i] > nums[insertIndex - 2])
                nums[insertIndex++] = nums[i];
        }

        return insertIndex;
    }

    @Test
    public void test() {
        int[] nums = {1,1,1,2,2,3};
        int k = removeDuplicates(nums);
        System.out.println(k);
    }
}
